RegistrationManager = null;

_RegistrationManager = function() {
 }
_RegistrationManager.prototype = {
Verify: function(Login, Password1,Password2,FirstName,MiddleName,SecondName,Gender,Age) {
		if(ValidationController.CreateAndAddValidationItemToStack(Login, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("Login is empty. Please enter Login", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(Password1, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("Password is empty. Please enter Password", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(FirstName, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("FirstName is empty. Please enter FirstName", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(MiddleName, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("MiddleName is empty. Please enter MiddleName", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(SecondName, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("SecondName is empty. Please enter SecondName", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(Gender, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("Gender is empty. Please enter Gender", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(ValidationController.CreateAndAddValidationItemToStack(Age, isNullOrEmpty).ValidateAndCleanStack().Result)
		{
			var nItem = NotificationManager.CreateNotification("Age is empty. Please enter Age", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		if(Password1 != Password2)
		{
			var nItem = NotificationManager.CreateNotification("Password and password confirmation don't coincide", ["error"]);
			NotificationManager.ShowMessages([nItem]);
			return;
		}
		CloakManager.OnCloak(false,true);
		var _RegistrationUser = ClientCommandsManager.Get("AddNewUserClientCommand");
		_RegistrationUser.Login = Login;
		_RegistrationUser.Password = $.md5(Password1);
		_RegistrationUser.FirstName = FirstName;
		_RegistrationUser.MiddleName = MiddleName;
		_RegistrationUser.SecondName = SecondName;
		_RegistrationUser.Gender = Gender;
		_RegistrationUser.Age = Age;
	    ClientCommandsManager.Execute(_RegistrationUser, this.SuccessHandler, null);
	},
	SuccessHandler: function(data, status, request) {
		CloakManager.OffCloak(true,true);
		if(data){
			var nItem = NotificationManager.CreateNotification("New user has been added", ["ok"]);
    		NotificationManager.ShowMessages([nItem]);
		}
		else{
			var nItem = NotificationManager.CreateNotification("Error. Login is already used.", ["error"]);
    		NotificationManager.ShowMessages([nItem]);
		}
    }
}